<?php
include 'Api.php';
include "Wechat.php";
header('Content-Type: text/html; charset=UTF-8');
$wxUserID=$_GET['wgateid'];
$wechat=new Wechat($wxUserID);
$bindFlag=$wechat->checkBindStatus();		
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<!-- Bootstrap -->
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>


</head>
<body>
	<div id="content">
	<?php  if($bindFlag==0){ ?>
		<h2>帐号绑定<small></small></h2><hr>
		<form role="form" method="post" action="bind.php">
		<br><br>
		  <div class="form-group col-xs-10 col-xs-offset-1">
		    <label for="exampleInputEmail1">学号</label>
		    <input type="text" class="form-control" id="studentid" name="studentid" placeholder="请输入学号">
		  </div><br><br><br><br><br><br>
		  <div class="form-group col-xs-10 col-xs-offset-1">
		    <label for="exampleInputPassword1">密码</label>
		    <input type="password" class="form-control" id="password" name="password" placeholder="请输入40网密码">
		  </div><br><br><br><br><br><br>
		  <input type="hidden" value="<?php echo $wxUserID;?>" name="wxuserid">
		  <button type="submit" class="btn btn-default col-xs-2 col-xs-offset-7">绑定</button>
		</form>
	<?php  }else{ ?>
		<br><br><br><br><br><br><br><br>
		<button id="close" class="btn btn-primary btn-lg col-xs-10 col-xs-offset-1">您的微信号已绑定</button>
		<script>

			var readyFunc = function onBridgeReady() {
			    var curid;
			    var curAudioId;
			    var playStatus = 0;
			 
			    
			    // 关闭当前webview窗口 - closeWindow
			    document.querySelector('#close').addEventListener('click', function(e){
			    	WeixinJSBridge.invoke('closeWindow',{
			        },function(res){
			            
			            //alert(res.err_msg);
			 
			       });
			    });    
			    
			}


			if (typeof WeixinJSBridge === "undefined") {
			  document.addEventListener('WeixinJSBridgeReady', readyFunc, false);
			} else {
			  readyFunc();
			}


		</script> 
	<?php  } ?>
	</div>

</body>
</html>
